package com.kang.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kang.entity.SysOperLog;
import com.kang.service.SysOperLogService;
import com.kang.util.WebResponse;
import com.kang.vo.SysOperLogQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "操作日志接口")
@RestController
@RequestMapping("/admin/system/sysOperLog")
@Slf4j
public class SysOperLogController {

    @Resource
    private SysOperLogService sysOperLogService;

    @ApiOperation(value = "获取操作日志分页列表")
    @GetMapping("{page}/{limit}")
    public WebResponse index(
            @ApiParam(name = "page", value = "当前页码", required = true) @PathVariable Integer page, @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit, @ApiParam(name = "sysOperLogVo", value = "查询对象", required = false)
                    SysOperLogQueryVo sysOperLogQueryVo) {
        try {
            Page<SysOperLog> pageParam = new Page<>(page, limit);
            return WebResponse.resSuccess("获取操作日志分页列表成功",sysOperLogService.selectByPage(pageParam,sysOperLogQueryVo));
        } catch (Exception e) {
            log.info("获取操作日志分页列表失败",e);
            return WebResponse.resFail("获取操作日志分页列表失败",null);
        }
    }

    @ApiOperation(value = "根据ID获取操作日志")
    @GetMapping("get/{id}")
    public WebResponse get(@PathVariable Integer id) {
        try {
            return WebResponse.resSuccess("根据ID获取操作日志成功",sysOperLogService.getById(id));
        } catch (Exception e) {
            log.info("根据ID获取操作日志失败",e);
            return WebResponse.resFail("根据ID获取操作日志失败",null);
        }
    }
}
